import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import br.com.faculdadeevolucao.controlebiblioteca.modelo.ConnectionFactory;

public class Insere {

	public static void main(String[] args) throws SQLException, ParseException {
		// conectando
		Connection con = new ConnectionFactory().getConnection();
		
		DateFormat fmt = new SimpleDateFormat("dd/MM/yyyy");  
		Date data = new Date(fmt.parse("01/01/1984").getTime());
		
		// cria um preparedStatement
		
		String sql = "insert into livrariaacademica.cliente"
				+ " (nome,email,endereco,dataNascimento)" + 
				" values (?,?,?,?)";
		
		PreparedStatement stmt = con.prepareStatement(sql);
		// preenche os valores
		stmt.setString(1, "Pedro");
		stmt.setString(2, "pedro@gmail.com");
		stmt.setString(3, "R. Vergueiro 3185 cj57");
		stmt.setDate(4, data);
		
		
		//stmt.setDate(4, new java.sql.Date(Calendar.getInstance()
		//		.getTimeInMillis()));
		
		// executa
		stmt.execute();
		stmt.close();
		System.out.println("Gravado!");
		con.close();
	}

}
